package com.bite.principle.component;

import com.bite.principle.model.Dog;
import jakarta.annotation.PostConstruct;
import jakarta.annotation.PreDestroy;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.BeanNameAware;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Slf4j
@Component
public class BeanLifeComponent implements BeanNameAware {

    private Dog singletonDog;

    public BeanLifeComponent() {
        log.info("执行构造函数");
    }

    @Autowired
    public BeanLifeComponent(Dog singletonDog) {
        this.singletonDog = singletonDog;
        log.info("构造方法注入");
    }
//    @Autowired
//    public void setSingletonDog(Dog singletonDog) {
//        this.singletonDog = singletonDog;
//        log.info("执行属性注入");
//    }

    @PostConstruct
    public void init(){
        log.info("执行init 方法");
    }

    public void use(){
        log.info("使用bean");
    }

    @PreDestroy
    public void preDestroy(){
        log.info("执行preDestroy方法");
    }

    @Override
    public void setBeanName(String name) {
        log.info("执行 setBeanName: " + name);
    }
}
